package com.usian;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext-redis.xml")
public class Hash {
    @Autowired
    private RedisTemplate redisTemplate;

    //存入
    @Test
    public void set(){
        redisTemplate.boundHashOps("zhu").put("a","1461");
        redisTemplate.boundHashOps("zhu").put("b","1464");
        redisTemplate.boundHashOps("zhu").put("c","1456");
        redisTemplate.boundHashOps("zhu").put("d","1466");
    }
    //查看key  取key
    @Test
    public void get(){
        Object zhu = redisTemplate.boundHashOps("zhu").keys();
        System.out.println(zhu);
    }
    //查看值 取值 value
    @Test
    public void testValue(){
        Object zhu = redisTemplate.boundHashOps("zhu").values();
        System.out.println(zhu);
    }
    //根据key取值
    @Test
    public void test(){
        Object zhu = redisTemplate.boundHashOps("zhu").get("a");
        System.out.println(zhu);
    }
    //根据key删除
    @Test
    public void delete(){
        redisTemplate.boundHashOps("zhu").delete("a");
    }
}
